﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace engine
{
    public partial class Form1 : Form
    {
        private HttpClient client = new HttpClient();
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private async void button1_Click(object sender, EventArgs e)
        {
            string keyword = keywordTextBox.Text;
            await Task.WhenAll(
                SearchAndDisplayResultsAsync("https://www.baidu.com/s?q=" + keyword, resultTextBox1),
                SearchAndDisplayResultsAsync("https://www.bing.com/search?q=" + keyword, resultTextBox2)
            );
        }

        private async Task SearchAndDisplayResultsAsync(string url, RichTextBox displayBox)
        {
           
            HttpResponseMessage response = await client.GetAsync(url);
            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();
                displayBox.Text = content.Substring(0, Math.Min(200, content.Length));
            }
            else
            {
                displayBox.Text = "Error fetching data.";
            }
        }
    }
}
